#include"TcpServer.hpp"
#include"Common.hpp"
#include"Dict.hpp"
#include"Command.hpp"
#include<functional>

std::string defaulthandler(const std::string &word)
{
    LOG(LogLevel::DEBUG) << "进入defaulthandle" ;
    std::string s = "haha ";
    s += word;
    return s;
}

void Usage(std::string proc)
{
    std::cerr<<"Usage: "<< proc << " port"<<std::endl;
}


int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);
    Enable_Console_Log_Strtegy();
    // //翻译
    // Dict d;
    // d.LoadDict();
    
    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,[&d](const std::string& word,InetAddr &peer)->std::string{
    //     return d.Translate(word,peer);
    // });

    
    Command cmd;
    func_t f = std::bind(&Command::Execute,&cmd,std::placeholders::_1,std::placeholders::_2);

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,f);
    tsvr->Init();
    tsvr->Run();
    return 0;
}